// 示例：使用新的初始化包创建简单服务
package main

import (
	"net/http"

	"github.com/gin-gonic/gin"
	"go.uber.org/zap"

	"yanxue_ai_go/pkg/common/initialize"
	"yanxue_ai_go/pkg/common/logger"
)

func main() {
	// 🚀 一行代码初始化所有依赖！
	initResult, err := initialize.InitializeService("agent")
	if err != nil {
		logger.Logger.Fatal("Failed to initialize service", zap.Error(err))
	}
	defer initResult.Cleanup()

	// 设置路由
	router := setupRouter()

	// 🎯 一行代码启动服务器并处理优雅关闭！
	if err := initialize.RunServer("agent", router, initResult.Config); err != nil {
		logger.Logger.Error("Server error", zap.Error(err))
	}
}

func setupRouter() *gin.Engine {
	router := gin.New()

	// 健康检查
	router.GET("/health", func(c *gin.Context) {
		// 使用内置健康检查
		deps := initialize.GetServiceDependencies("agent")
		if err := initialize.HealthCheck(deps); err != nil {
			c.JSON(http.StatusInternalServerError, gin.H{
				"status": "unhealthy",
				"error":  err.Error(),
			})
			return
		}

		c.JSON(http.StatusOK, gin.H{
			"status":  "healthy",
			"service": "agent",
		})
	})

	// 示例API
	router.GET("/api/v1/example", func(c *gin.Context) {
		c.JSON(http.StatusOK, gin.H{
			"message": "Hello from simplified service!",
		})
	})

	return router
}
